var request = require('../../utils/request');

Page({
  data: {
    value: "",
    valueChange:""
  },

  getNum: function () {
    //获取验证码
    var id = wx.getStorageSync('sessionId');
    var num = parseInt(this.data.valueChange);
    var data = {
      'self:sms:generate':{
        'sms_type':'verification',
        'mobile':num,
        'wx_session':id
      }
    }
    request.post({
      path: '/wxapp_api/api'
    },data)
      .then(function (res) {
        var retData = res['self:sms:generate'];
        if (retData.ret != 0) {
          wx.showModal({
            content: retData.msg,
            showCancel:false
          })
          return;
        }
      });
    var url = "../has-link2/has-link2"
    wx.navigateTo({
      url: url
    })
  },

  onShow: function(){
    var mobile = wx.getStorageSync('mobile');
    var reg = /^(\d{3})(\d{4})(\d{4})$/;
    var matches = reg.exec(mobile);
    var newNum = matches[1] + ' ' + matches[2] + ' ' + matches[3];
    this.setData({
      value:newNum,
      valueChange:mobile
    });
  },

  goback: function(){
    wx.navigateBack({
      delta : 1
    })
  },
  
  gohome: function(){
    wx.switchTab({ 
      url: '../new-index/index', 
      success: function (e) { 
        var page = getCurrentPages().pop(); 
        if (page == undefined || page == null) return; 
        page.onLoad(); 
      } 
    })
  }
 
});


